문서의 임의 삭제는 제재 대상으로, 문서를 삭제하려면 삭제 토론을 진행해야 합니다. 문서 보기문서 삭제토론 Go(프로그래밍 언어) (문단 편집) == 예시 == Go는 Python과 동일하게 탭 문자로 들여쓰기를 하는 것이 원칙이다. [[https://golang.org/cmd/gofmt/|#]] * [[Hello, world!]] {{{#!syntax go package main // main() 함수를 포함하는 패키지의 이름이 main이 아닐 경우 에러가 발생한다. import "fmt" func main() { fmt.Println("Hello, world!") } }}} * Example of Printf {{{#!syntax go package main import "fmt" func main() { fmt.Printf("%d %d\n", 32, 132); } }}} * Hello world example of Cgo[* Go의 [[C(프로그래밍 언어)|C]] 코드를 위한 FFI(Foreign Function Interface)이다.] {{{#!syntax go package main /* #include */ import "C" func main() { C.puts("Hello world!") } }}} * Example of goroutine: http {{{#!syntax go package main import ( "fmt" "net/http" ) var c = make(chan *http.Response) func head(url string) { resp, _ := http.Head(url) c <- resp } func main() { // HEAD 요청을 동시에 실행한다. go head("https://namu.wiki") go head("https://www.google.com") go head("https://golang.org") for i := 0; i < 3; i++ { resp := <-c if resp != nil { resp.Body.Close() fmt.Printf("%v: %s\n", resp.Request.URL, resp.Status) continue } fmt.Printf("%v: 연결 실패\n", resp.Request.URL) } } }}} * Example of select statement: timeout {{{#!syntax go package main import ( "fmt" "net/http" "time" ) func main() { c := make(chan string) go func() { resp, err := http.Head("https://namu.wiki") if err == nil { resp.Body.Close() c <- resp.Status return } c <- "연결 실패" }() // 연결 시간 초과 알림을 select로 구현할 수 있다. select { case status := <-c: fmt.Println(status) case <-time.After(2 * time.Second): fmt.Println("시간 초과") } } }}}저장 버튼을 클릭하면 당신이 기여한 내용을 CC-BY-NC-SA 2.0 KR으로 배포하고,기여한 문서에 대한 하이퍼링크나 URL을 이용하여 저작자 표시를 하는 것으로 충분하다는 데 동의하는 것입니다.이 동의는 철회할 수 없습니다.캡챠저장미리보기